package com.niit.sum.schoolsum;


import com.niit.bean.StudentCountBean;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;


public class SchoolSumReducer extends Reducer<Text, StudentCountBean,Text,StudentCountBean> {
    StudentCountBean outValue = new StudentCountBean();

    @Override
    protected void reduce(Text key, Iterable<StudentCountBean> values, Context context) throws IOException, InterruptedException {
        /**
         * 创建统计变量
         */
        long totalActiveDays = 0;
        long totalStudentsNum = 0;

        for(StudentCountBean value:values){
            totalActiveDays += value.getActiveDays();
            totalStudentsNum += value.getStudentsNum();
        }

        /**
         * 输出结果赋值
         */
        outValue.set(totalActiveDays,totalStudentsNum);

        context.write(key , outValue);


    }
}
